package cn.lu.controller;

import cn.lu.dao.CurriculumMapper;
import cn.lu.pojo.Chapter;
import cn.lu.pojo.Curriculum;
import cn.lu.service.CurriculumService;
import cn.lu.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 课程
 */
@Controller
@RequestMapping("/curriculum")
@ResponseBody
public class CurriculumController {

    @Autowired
    private CurriculumService curriculumService;

    @RequestMapping(value = "/admin",method = RequestMethod.POST)
    public Result insert(@RequestBody Curriculum curriculum){
        return new Result().success(curriculumService.addCurriculum(curriculum));
    }

    @RequestMapping(value = "",method = RequestMethod.GET)
    public Result selectById(@RequestParam(value = "curriculumId",required = false)Integer curriculumId,HttpServletRequest request){
        return new Result().success(curriculumService.selectByIdAndUserId(curriculumId,Integer.parseInt(request.getHeader("userId"))));
    }

    @RequestMapping(value = "",method = RequestMethod.DELETE)
    public Result deleteById(@RequestParam(value = "curriculumId")Integer curriculumId, HttpServletRequest request){
        return new Result().success(curriculumService.deleteByIdAndUserId(curriculumId,Integer.parseInt(request.getHeader("userId"))));
    }


    @RequestMapping(value = "",method = RequestMethod.PUT)
    public Result updateByIdAndUserId(@RequestBody Curriculum curriculum,HttpServletRequest request){
        return new Result().success(curriculumService.updateByIdAndUserId(curriculum,Integer.parseInt(request.getHeader("userId"))));
    }


    @RequestMapping(value = "",method = RequestMethod.POST)
    public Result addInTheUserId(@RequestBody Curriculum curriculum, HttpServletRequest request){
        return curriculumService.addInTheUserId(curriculum,Integer.parseInt(request.getHeader("userId")));
    }











}